package com.kunda.netty.protocol.service;

import org.springframework.stereotype.Service;

import com.google.protobuf.GeneratedMessage;
import com.kunda.netty.protocol.RHMS.Header;
import com.kunda.netty.protocol.RHMS.LoginRequest;
import com.kunda.netty.protocol.RHMS.LoginResponse;
import com.kunda.netty.protocol.RHMS.LogoutResponse;
import com.kunda.netty.protocol.RHMS.MsgType;
import com.kunda.netty.protocol.annotation.RequestHandler;

@Service
public class LoginRequestService {

	@RequestHandler(MsgType.M_LoginRequest)
	public GeneratedMessage doLogin(GeneratedMessage message) {
		LoginRequest request = (LoginRequest)message;
		
		LoginResponse response = LoginResponse.newBuilder()
				.setHeader(Header.newBuilder().setCode(0).setSuccess(true).setMessage("ok").build())
				.setAccount(request.getAccount())
				.setAge(18)
				.setUid("user001")
				.build();
		
		return response;
	}
	
	@RequestHandler(MsgType.M_LogoutRequest)
	public GeneratedMessage doLogout(GeneratedMessage message) {
		LoginRequest request = (LoginRequest)message;
		
		LogoutResponse response = LogoutResponse.newBuilder()
				.setHeader(Header.newBuilder().setCode(0).setSuccess(true).setMessage("ok").build())
				.setAccount(request.getAccount())
				.setUid("user001")
				.build();
		
		return response;
	}

}
